package com.ftd.model;

import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * Created by apple on 2016/12/8.
 */
@Component
@Entity
@Table(name = "user_book", schema = "JavaWeb", catalog = "")
@IdClass(BorrowPK.class)
public class Borrow  implements Serializable {
    private int bookId;
    private int userId;
    private Timestamp creatTime;
    private Timestamp backTime;
    private Integer leftDay;
    private Integer delayDay;
    private Integer borrowCount;

    @Id
    @Column(name = "book_id")
    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {
        this.bookId = bookId;
    }

    @Id
    @Column(name = "user_id")
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "creat_time")
    public Timestamp getCreatTime() {
        return creatTime;
    }

    public void setCreatTime(Timestamp creatTime) {
        this.creatTime = creatTime;
    }

    @Basic
    @Column(name = "back_time")
    public Timestamp getBackTime() {
        return backTime;
    }

    public void setBackTime(Timestamp backTime) {
        this.backTime = backTime;
    }

    @Basic
    @Column(name = "left_day")
    public Integer getLeftDay() {
        return leftDay;
    }

    public void setLeftDay(Integer leftDay) {
        this.leftDay = leftDay;
    }

    @Basic
    @Column(name = "delay_day")
    public Integer getDelayDay() {
        return delayDay;
    }

    public void setDelayDay(Integer delayDay) {
        this.delayDay = delayDay;
    }

    @Basic
    @Column(name = "borrow_count")
    public Integer getBorrowCount() {
        return borrowCount;
    }

    public void setBorrowCount(Integer borrowCount) {
        this.borrowCount = borrowCount;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Borrow userBook = (Borrow) o;

        if (bookId != userBook.bookId) return false;
        if (userId != userBook.userId) return false;
        if (creatTime != null ? !creatTime.equals(userBook.creatTime) : userBook.creatTime != null) return false;
        if (backTime != null ? !backTime.equals(userBook.backTime) : userBook.backTime != null) return false;
        if (leftDay != null ? !leftDay.equals(userBook.leftDay) : userBook.leftDay != null) return false;
        if (delayDay != null ? !delayDay.equals(userBook.delayDay) : userBook.delayDay != null) return false;
        if (borrowCount != null ? !borrowCount.equals(userBook.borrowCount) : userBook.borrowCount != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = bookId;
        result = 31 * result + userId;
        result = 31 * result + (creatTime != null ? creatTime.hashCode() : 0);
        result = 31 * result + (backTime != null ? backTime.hashCode() : 0);
        result = 31 * result + (leftDay != null ? leftDay.hashCode() : 0);
        result = 31 * result + (delayDay != null ? delayDay.hashCode() : 0);
        result = 31 * result + (borrowCount != null ? borrowCount.hashCode() : 0);
        return result;
    }
}
